<template>
  <div>
    <input v-model="loginForm.username" type="text" placeholder="用户名">
    <input v-model="loginForm.password" type="text" placeholder="密码">
    <button @click="login">登录</button>
  </div>
</template>

<script>
  import { mapMutations } from 'vuex'
  export default {
    name: 'login',
    data() {
      return {
        loginForm: {
          username: '',
          password: ''
        }
      }
    },

    methods: {
      ...mapMutations(['changeLogin']),
      login() {
        const _this = this
        if (this.loginForm.username === '' || this.loginForm.password === '') {
          alert('账号或密码不能为空')
        } else {
          this.$http({
            method: 'post',
            url: '/user/login',
            data: _this.loginForm
          }).then(res => {
            console.log(res)
            if(res){
              // _this.$router.push('/home')
              // alert('登陆成功')
            }
          }).catch(error => {
            alert('登录异常，请告知管理员处理')
            console.log(error)
          })
        }
      }
    }
  }
</script>
